const router = require('koa-router')();
const controller = require('../controller/c-posts')

router.prefix('/article')

// 重置到文章页
// router.get('/', controller.getRedirectPosts)
/**
 * @swagger
 * definition:
 *  homeParam:
 *      properties:
 *          page:
 *              type: string
 *  selfParam:
 *      properties:
 *          name:
 *              type: string
 *          page:
 *              type: string
 *  articleParam: 
 *      properties:
 *          title:
 *              type: string
 *          content:
 *              type: string
 *          type:
 *              type: string
 *          recom:
 *              type: string
 *  commentParam: 
 *      properties:
 *          postId:
 *              type: string
 *          content:
 *              type: string
 *  updateParam:
 *       properties:
 *          postId:
 *              type: string
 *          content:
 *              type: string
 *          title:
 *              type: string
 *  removeParam:
 *       properties:
 *          postId:
 *              type: string
 *  delComtParam:
 *       properties:
 *          postId:
 *              type: string
 *          commentId:
 *              type: string
 *  comtPageParam:
 *       properties:
 *          postId:
 *              type: string
 *          commentId:
 *              type: string
 */

/**
 * @swagger
 * /article/posts:
 *   get:
 *     summary: 获取文章信息列表接口
 *     description: 获取文章信息列表的应用
 *     tags:
 *       - 文章管理
 *     produces:
 *       - application/json
 *     responses:
 *       200:
 *         description: 成功获取
 */
// 获取文章信息列表
router.get('/posts', controller.getPosts)

/**
 * @swagger
 * /article/page:
 *   post:
 *     summary: 首页分页，每次输出10条
 *     description: 编辑文章信息并发表文章的应用
 *     tags:
 *       - 文章管理
 *     produces:
 *       - application/json
 *     parameters:
 *       - name: params
 *         in: body
 *         required: true
 *         schema:
 *            $ref: '#/definitions/homeParam'
 *     responses:
 *       200:
 *         description: 发布成功
 */
// 首页分页，每次输出10条
router.post('/page', controller.postPostsPage)

/**
 * @swagger
 * /article/self:
 *   post:
 *     summary: 个人文章分页，每次输出10条
 *     description: 编辑文章信息并发表文章的应用
 *     tags:
 *       - 文章管理
 *     produces:
 *       - application/json
 *     parameters:
 *       - name: params
 *         in: body
 *         required: true
 *         schema:
 *            $ref: '#/definitions/selfParam'
 *     responses:
 *       200:
 *         description: 发布成功
 */
// 个人文章分页，每次输出10条
router.post('/self', controller.postSelfPage)

// 单篇文章页
// router.get('/posts/:postId', controller.getSinglePosts)

// 发表文章页面
// router.get('/create', controller.getCreate)

/**
 * @swagger
 * /article/create:
 *   post:
 *     summary: 发表文章接口
 *     description: 编辑文章信息并发表文章的应用
 *     tags:
 *       - 文章管理
 *     produces:
 *       - application/json
 *     parameters:
 *       - name: params
 *         in: body
 *         required: true
 *         schema:
 *            $ref: '#/definitions/articleParam'
 *     responses:
 *       200:
 *         description: 发布成功
 */
// post 发表文章
router.post('/create', controller.postCreate)

/**
 * @swagger
 * /article/comment:
 *   post:
 *     summary: 发表评论接口
 *     description: 编辑发布评论信息的应用
 *     tags:
 *       - 文章管理
 *     produces:
 *       - application/json
 *     parameters:
 *       - name: params
 *         in: body
 *         required: true
 *         schema:
 *            $ref: '#/definitions/commentParam'
 *     responses:
 *       200:
 *         description: 评论成功
 */
// 发表评论
router.post('/comment', controller.postComment)

// 编辑单篇文章页面
// router.get('/posts/:postId/edit', controller.getEditPage)

/**
 * @swagger
 * /article/edit:
 *   put:
 *     summary: 更新单篇文章信息接口
 *     description: 更新单篇文章信息的应用
 *     tags:
 *       - 文章管理
 *     produces:
 *       - application/json
 *     parameters:
 *       - name: params
 *         in: body
 *         required: true
 *         schema:
 *            $ref: '#/definitions/updateParam'
 *     responses:
 *       200:
 *         description: 发布成功
 */
// post 编辑更新单篇文章
router.put('/edit', controller.postEditPage)

/**
 * @swagger
 * /article/remove:
 *   delete:
 *     summary: 删除单篇文章接口
 *     description: 删除单篇文章信息的应用
 *     tags:
 *       - 文章管理
 *     produces:
 *       - application/json
 *     parameters:
 *       - name: params
 *         in: body
 *         required: true
 *         schema:
 *            $ref: '#/definitions/removeParam'
 *     responses:
 *       200:
 *         description: 删除文章成功
 */
// 删除单篇文章
router.delete('/remove', controller.postDeletePost)

/**
 * @swagger
 * /article/comment/remove:
 *   delete:
 *     summary: 删除评论信息接口
 *     description: 删除单篇文章指定ID评论信息的应用
 *     tags:
 *       - 文章管理
 *     produces:
 *       - application/json
 *     parameters:
 *       - name: params
 *         in: body
 *         required: true
 *         schema:
 *            $ref: '#/definitions/delComtParam'
 *     responses:
 *       200:
 *         description: 删除评论成功
 */
// 删除评论
router.delete('/comment/remove', controller.postDeleteComment)

/**
 * @swagger
 * /article/commentPage:
 *   post:
 *     summary: 获取评论分页接口
 *     description: 获取评论分页信息的应用
 *     tags:
 *       - 文章管理
 *     produces:
 *       - application/json
 *     parameters:
 *       - name: params
 *         in: body
 *         required: true
 *         schema:
 *            $ref: '#/definitions/comtPageParam'
 *     responses:
 *       200:
 *         description: 分页数据获取成功
 */
// 评论分页
router.post('/commentPage', controller.postCommentPage)

module.exports = router